# NOTE:
# I am a fucker builder, I don't provide any safe PKGBUILD
# and I always install to /usr/local/bin/ 

# must define
pkgname=tv
pkgrel=1
pkgver=0.0.1
pkgdesc="terminal viewer"
arch=('x86_64') #this is an array
license=('GPLv2') #this is an array
sha512sums=('SKIP')
depends=('libwebp' 'pandoc' 'libjpeg-turbo' 'libexif' 'graphicsmagick' 'ffmpeg' 'openslide' 'libsixel' 'libdeflate' 'librsvg' 'poppler-glib')
makedepends=('cmake' 'pandoc' 'ninja' 'pkgconf' 'git' 'gcc')

# NOTE: make sure this source is not dead
source=("https://gitee.com/nidielaila/this-term-todos/releases/download/linux-tv.tar.gz/linux-tv.tar.gz")

build() {
  #default in dir src
  echo "NOTE: +++++++++++++++++" ${PWD}
  # I not using $srcdir
  
  cd ..
  echo "NOTE: +++++++++++++++++" ${PWD}
  #rm -rf pkg src
  tar xvfz linux-tv.tar.gz
  
  cd docs
  pandoc tv.md -s -t man -o tv.1
  cd ../src
  ./create-manpage-inc.sh
  #echo '#define TV_VERSION "0.0.1"' >> tv_version.h
  cd .. 

  cmake -B build -G "Ninja"
  cmake --build build
}

package() {
  echo "NOTE: ++++++++++++++++++++=" ${srcdir}
  echo "NOTE: ++++++++++++++++++++=" ${pkgdir}

  echo "NOTE: +++++++++++++++++++++" ${PWD}
  cd ..
  strip -S -s -x build/bin/tv 
  # install tv not tv.1
  sudo cp build/bin/tv /usr/local/bin/tv 
}
